package com.xxgc.spring.controller;

import com.xxgc.spring.bean.Users;
import com.xxgc.spring.bean.UserExtend;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName LiveController
 * @Description: TODO
 * @Author 石嘉懿
 * @Date 2021/11/10
 * @Version V1.0
 **/
@Controller
@RequestMapping("/live")
public class LiveController {


    @ResponseBody
    @RequestMapping("/live1")
    public String userLive(
                            Integer liveId,
                            @RequestParam(value = "livename",required = true,defaultValue = "李四") String liveName){
        System.out.println("获取到了数据");

        System.out.println("直播间id = " + liveId);
        System.out.println("直播间name = " + liveName);
        return liveName;
    }

    @ResponseBody
    @RequestMapping("/live2")
    public Users userLive2(Users users){
        System.out.println(users);
        return users;
    }

    @ResponseBody
    @RequestMapping("/live3")
    public String[] userLive3(String[] names){
        List<String> strings = Arrays.asList(names);
        //打印数组的第二种方式
        //String s = Arrays.toString(names);
        System.out.println(strings);
        return names;
    }

    @ResponseBody
    @RequestMapping("/live4")
    public void userLive4(UserExtend ue){
        for (Users users : ue.getUserList()) {
            System.out.println("users = " + users);
        }
    }

    @ResponseBody
    @RequestMapping("/live5")
    public void userLive5(@RequestBody List<Users> users){
        for (Users user : users) {
            System.out.println("user = " + user);
        }
    }

}
